<template>
<div class="icons">
   <swiper :options="swiperOption">
    <swiper-slide v-for="(page,index) in pages" :key="index">
      <router-link :to="'/item-list/'+item.title" tag="dl" class="icon" v-for="item of page" :key="item.id">
        <dt><img :src="item.src"/></dt>
        <dd>{{item.title}}</dd>
      </router-link>
    </swiper-slide>
    <div class="swiper-pagination"  slot="pagination"></div>
  </swiper>
</div>
</template>

<script>
export default {
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  props: {
    'list': Array
  },
  computed: {
    pages () {
      let pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor(index / 8)
        // 初始化一维数据
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>

@import '~_style/var.styl'

.swiper-pagination-bullets
  bottom:0
.icons >>> .swiper-pagination-bullet-active
  background:$bgColor
.icons >>> .swiper-container
  padding-bottom:.2rem
  overflow:initial
.icons
  width:100%
  height:0
  padding:.1rem 0
  padding-bottom:54%
  overflow: hidden;
  .icon
    float:left
    width:25%
    height:0
    padding-bottom:25%
    text-align:center
    overflow: hidden
    font-size:.30rem
    img
      width:70%
      padding: .05rem 0
    dd
      color:#333
      ellipsis()
</style>
